package com.hu.zhcc.shiro.controller;

import com.github.pagehelper.PageInfo;
import com.hu.zhcc.shiro.entity.bo.Template;
import com.hu.zhcc.shiro.entity.vo.TemplateVO;
import com.hu.zhcc.shiro.service.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * 体质评估
 */

@RestController
@CrossOrigin
@RequestMapping("/template")
public class TemplateController {
    @Autowired
    private TemplateService TemplateService;

    @GetMapping("")
    @ResponseBody
    public PageInfo<Template> homeTemplate(TemplateVO TemplateVO){
        PageInfo<Template> TemplatePageInfo = TemplateService.pageQuery(TemplateVO);
        return TemplatePageInfo;
    }

    @PostMapping("")
    public ResponseEntity<?> saveCheckitem(@RequestBody Template Template) {
        return TemplateService.AddTemplate(Template) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }
    @DeleteMapping("/{id}")
    public ResponseEntity<?> removeTemplate(@PathVariable("id") Short id) {
        return TemplateService.removeTemplate(id) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }

    @PutMapping("/{id}")
    public ResponseEntity<Integer> updateRouter(@PathVariable("id") int id, @RequestBody Template Template) {
        return TemplateService.updateTemplate(Template) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }
    @GetMapping("/{id}")
    public ResponseEntity<?> upTemplate(@PathVariable("id") Short id) {
        return TemplateService.updateTemplate(id) ? ResponseEntity.noContent().build() :
                ResponseEntity.notFound().build();
    }
}
